package org.upt.dcda.presentation;

import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.upt.dcda.AuthorManager;
import org.upt.dcda.AuthorManagerBeanRemote;
import org.upt.dcda.db.AuthorEntity;

public class AuthorInformation
{

	@EJB
	private AuthorManagerBeanRemote	authorManagerBean;

	public List<AuthorEntity> getAllAuthors(HttpServletRequest request,
			HttpServletResponse response)
	{
		List<AuthorEntity> authors = null;
		try
		{
			InitialContext initContext = new InitialContext();
			this.authorManagerBean = (AuthorManagerBeanRemote) initContext
					.lookup(AuthorManager.AUTHOR_BEAN_NAME);

			authors = this.authorManagerBean.getAllAuthors();

		}
		catch (Throwable be)
		{
			try
			{
				request.getServletContext().log("Caught Exception: " + be, be);
				response.sendError(
						HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
						be.toString());
			}
			catch (IOException e)
			{
				request.getServletContext().log("Caught IOException: " + e, e);
			}
		}
		return authors;
	}
}
